package com.rsstuan.subscribe;


import org.mortbay.log.Log;

import com.rsstuan.data.Channel;
import com.rsstuan.storage.IChannelStorage;
import com.rsstuan.storage.impl.GoogleChannelStorage;
import com.rsstuan.utils.IdUtils;

public class Subscriber {
	IChannelStorage storage;
	
	public Subscriber() {
		storage = new GoogleChannelStorage();
	}
	
	public void subscribe(String feedUrl) {
		try {
			Long channelId = IdUtils.generateFeedId(feedUrl);
			Channel channel = storage.getChannel(channelId);
			if ( channel != null) {
				Log.warn("channel already exist with channelId = " + channelId);
				return;
			}
			channel = new Channel();
			channel.setId(channelId);
			channel.setFeedUrl(feedUrl);
			

			storage.saveChannel(channel);
			
		} catch (Exception e) {
		}
		
	}

}
